home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_368 / newex / newex.asm < prev    next >
Assembly Source File  |  1992-05-06  |  16KB  |  362 lines

  1.  
  2. ;            NewEx.asm   90-06-11  Version V1.1
  3. ;
  4. ;            New Executeing program
  5. ;
  6. ;            Written by Kjell Cederfeldt in June - 90.
  7. ;
  8. ExecBase           = 4
  9. OpenLibrary        = -408         ; exec offset       OpenLibrary(libName,version)(A1,D0)
  10. CloseLibrary       = -414         ; exec offset       CloseLibrary(library)(a1)
  11. FindTask           = -294         ; exec offset       FindTask(name)(a1)
  12. WaitPort           = -384         ; exec offset       WaitPort(port)(a0)
  13. GetMsg             = -372         ; exec offset       GetMsg(port)(a0)
  14. ReplayMsg          = -378         ; exec offset       ReplayMsg(message)(a1)
  15. Forbid             = -132         ; exec offset       Forbid()
  16. Open               = -30          ; dos offset        Open(name,accessMode)(D1/D2)
  17. Close              = -36          ; dos offset        Close(file)(D1)
  18. Write              = -48          ; dos offset        Write(file,buffer,length)(d1/d2/d3)
  19. OutPut             = -60          ; dos offset        OutPut()
  20. Lock               = -84          ; dos offset!       Lock(name,mode)(d1,d2)
  21. UnLock             = -90          ; dos offset!       UnLock(lock)(d1)
  22. Examine            = -102         ; dos offset!       Examine(Lock,InfoBlock)(d1,d2)
  23. CurrentDir         = -126         ; dos offset        CurrentDir(lock)(d1)
  24. ParentDir          = -210         ; dos offset!       ParentDir(lock)(d1)
  25. Execute            = -222         ; dos offset        Execute(string,file,file)(D1/D2/D3)
  26. GetDiskObject      = -78          ; icon offset       GetDiskObject(name)(a0)
  27. FindToolType       = -96          ; icon offset       FindToolType(toolTypeArray,typeName)(A0/A1)
  28. FreeDiskObject     = -90          ; icon offset       FreeDiskObject(diskobj)(a0)
  29. Mode_old           = 1005         ;
  30. Mode_new           = 1006         ;
  31. Access_read        = -2
  32.  
  33.                    move.l sp,Initial_SP               ;Save stackpointer
  34.                    move.l a0,Filename                 ;CLI=true save address to argument
  35.                    sub.l  #1,d0                       ;decrement lenth with 1
  36.                    add.l  d0,a0                       ;Add lenth to address
  37.                    move.b #0,(a0)                     ;clear last byte (CLI=0A)
  38.                    move.l #0,RetCode                  ;clear Returncode
  39.  
  40. START:             move.l ExecBase,a6
  41.                    suba.l a1,a1                       ;Find this Task
  42.                    jsr    Findtask(a6)                
  43.                    move.l d0,a4                       ;Save strukture in a4
  44.                    tst.l  $ac(a4)                     ;CLI or WB ?
  45.                    bne    CliStart                    ;
  46.  
  47.  
  48. ;       ** This only when  start from WB
  49.  
  50.  
  51.                    move.l #49,RetCode                 ;Set Returncode
  52.                    lea    $5c(a4),a0                  ;WBench message
  53.                    jsr    WaitPort(a6)                ;wait
  54.                    jsr    GetMsg(a6)                  ;load message
  55.                    move.l d0,Message                  ;save pointer to WBMessage
  56.                    beq    Slut                        ;error!
  57.  
  58.                    move.l #48,RetCode                 ;Set Returncode
  59.                    move.l Message,a0                  ;Pointer to WBMessage
  60.                    move.l $24(a0),a0                  ;Argumentlist
  61.                    beq    Slut2                       ;no agument
  62.  
  63. CliStart:
  64.  
  65.  
  66. ;   Open icon.library
  67.  
  68.                    move.l #47,RetCode                 ;Set Returncode
  69.                    lea    Iconname(pc),a1             ;Load address of IconName in a1
  70.                    clr.l  d0                          ;all version
  71.                    jsr    OpenLibrary(a6)             ;open iconlibrary
  72.                    move.l d0,Iconbase                 ;Save Iconbase
  73.                    beq    Error1                      ;branch if error!
  74.  
  75.  
  76. ;   open dos.library
  77.  
  78.                    move.l #46,RetCode                 ;Set Returncode
  79.                    lea    Dosname(pc),a1              ;Load address of DosName in a1
  80.                    clr.l  d0                          ;all dosversion
  81.                    jsr    OpenLibrary(a6)             ;open doslibrary
  82.                    move.l d0,Dosbase                  ;Save Dosbase
  83.                    beq    Error2                      ;branch if error!
  84.  
  85.  
  86.                    jsr    PointTOCLI                  ;Get CLI pointer
  87.  
  88.                    tst.l  Message                     ;if start from CLI
  89.                    beq    InFileOpen                  ;branch to FileOpens
  90.  
  91. ;   set Current directory
  92.  
  93.                    move.l #45,RetCode                 ;Set Returncode
  94.                    move.l Message,a0                  ;Pointer to WBMessage sm_ArgList
  95.                    move.l $24(a0),a0                  ;move pointer to wa_Lock
  96.                    beq    Error3                      ;Error!
  97.  
  98.                    move.l (a0),d1                     ;D1 => Lock
  99.                    move.l Dosbase,a6
  100.                    jsr    CurrentDir(a6)              ;Lock Current Dir
  101.  
  102. ;   Get diskobject (.info file)
  103.  
  104.                    move.l #44,RetCode                 ;Set Returncode
  105.                    move.l Message,a0
  106.                    move.l $24(a0),a0
  107.                    move.l 4(a0),a0                    ;move pointer to wa_Name
  108.                    move.l a0,Filename
  109.                    move.l Iconbase,a6
  110.                    jsr    GetDiskObject(a6)           ;Get diskobject
  111.                    move.l d0,Diskobj                  ;Save diskobject
  112.                    beq    Error3                      ;Error!
  113.                    move.l d0,a1
  114.                    move.l $36(a1),a1                  ;pointer to ToolType Array
  115.                    move.l a1,toolTypeArray            ;save pointer
  116.  
  117.  
  118.  
  119. ;            *** Get argument from tool icon (tooltype)
  120.  
  121.                    move.l Iconbase,a6
  122.                    move.l toolTypeArray,a0
  123.                    move.l #typeName1,a1
  124.                    jsr    FindToolType(a6)
  125.                    move.l d0,Inname
  126.  
  127.                    move.l toolTypeArray,a0
  128.                    move.l #typeName2,a1
  129.                    jsr    FindToolType(a6)
  130.                    move.l d0,Outname
  131.  
  132.  
  133. ;   open outfile
  134.                    move.l #43,RetCode                 ;Set Returncode
  135.                    move.l DosBase,a6                  ;Load dosbase
  136.                    move.l Outname,d1                  ;Get filename
  137.                    move.l #Mode_new,d2                ;1006=NewFile: 1005=Existing file
  138.                    jsr    Open(a6)                    ;open file
  139.                    move.l d0,Outhandle                ;Save filehandler
  140.                    beq    Error3                      ;Branch if error!
  141.  
  142. ;-------
  143. ;   open readfile
  144. ;-------
  145. InFileOpen:
  146.  
  147.                    move.l #42,RetCode                 ;Set Returncode
  148.                    move.l Filename,d1                 ;Load filename
  149.                    tst.l  Message                     ;test if Start WB or CLI?
  150.                    beq.s  InopLab                     ;Branch, if CLI
  151.                    move.l Inname,d1                   ;Load filename
  152. InOpLab:           move   #Mode_old,d2                ;1005=Existing file : 1006=NewFile
  153.                    move.l DosBase,a6                  ;Load dosbase
  154.                    jsr    Open(a6)                    ;open file
  155.                    move.l d0,Inhandle                 ;Save filehandlern
  156.                    bne    BldPath                     ;Branch if NOT error!
  157.  
  158.                    tst.l  Message                     ;test Start WB or CLI?
  159.                    bne.s  Err                         ;Branch, if WB
  160.                    move.l CLIpoint,d1
  161.                    move.l #Textfld,d2
  162.                    move.l #84,d3
  163.                    jsr    Write(a6)
  164. Err:               bra    Error4
  165.  
  166.  
  167. ;             Get and build pathway.
  168.  
  169. BldPath:           jsr    GetPath                     ;build path
  170.  
  171.  
  172. Skriv:    ; Only for bebuging (not used in program)
  173.                    move.l Dosbase,a6
  174. ;                   move.l CLIpoint,d1
  175. ;                   tst.l  Message                     ;test if Start WB or CLI?
  176. ;                   beq.s  Skr                         ;Branch to End if CLI
  177. ;                   move.l Outhandle,d1
  178. ;Skr:               move.l #path,d2
  179. ;                   move.l #255,d3                      ;string length
  180. ;                   jsr    Write(a6)
  181. ;--------
  182. ;   call Execute (dosfunction)
  183. ;--------
  184.                    move.l #0,RetCode                 ;clear Returncode
  185.                    move.l CLIPoint,d3
  186.  
  187.                    tst.l  Message                     ;test if Start WB or CLI?
  188.                    beq.s  Exlabel                     ;Branch to End if CLI
  189.  
  190.                    move.l Outhandle,d3                ;Get file handler
  191. Exlabel:           move.l PathStart,d1                ;get pointer of string
  192.                    move.l InHandle,d2                 ;get file handler
  193.                    jsr    Execute(a6)                 ;exectue a scripfile (dos)
  194.  
  195.  
  196. ;---------
  197. ;   Close files
  198. ;---------
  199.  
  200. Cleanup1:          move.l Inhandle,d1
  201.                    jsr    Close(a6)
  202.  
  203. Error4:            tst.l  Message                     ;test if Start WB or CLI?
  204.                    beq.s  temp                        ;Branch to End if CLI
  205.  
  206.                    move.l Outhandle,d1
  207.                    jsr    Close(a6)
  208.  
  209.  
  210. Error3:            move.l Iconbase,a6                 ;Load Iconbase
  211.                    move.l Diskobj,a0                  ;Get diskobject strukture
  212.                    jsr    FreeDiskobject(a6)          ;Free Diskobjec
  213.  
  214. temp:              move.l Dosbase,a1                  ;Load Dosbase
  215.                    move.l Execbase,a6
  216.                    jsr    CloseLibrary(a6)            ;Close Doslibrary:
  217.  
  218. Error2:            move.l Iconbase,a1                 ;Load IconBase
  219.                    move.l Execbase,a6
  220.                    jsr    CloseLibrary(a6)            ;Close Iconlibrary
  221.  
  222.  
  223. Error1:            tst.l  Message                     ;Test if Start WB or CLI?
  224.                    beq.s  Slut                        ;Branch to End if CLI
  225. Slut2:             jsr    Forbid(a6)
  226.                    move.l Message,a1
  227.                    jsr    ReplayMsg(a6)               ;drop struktur
  228.  
  229. Slut:              move.l Initial_SP,sp               ;Load start stack
  230.                    clr.l  d0
  231.                    move.l RetCode,d0                  ;Get returncode to D0
  232.                    rts
  233.  
  234. ;       !!    *********** System DATA **************  !!
  235.  
  236. Initial_SP:        dc.l   0
  237. RetCode:           dc.l   0
  238. Iconbase:          dc.l   0
  239. Dosbase:           dc.l   0
  240. Inhandle:          dc.l   0
  241. Outhandle:         dc.l   0
  242. Message:           dc.l   0
  243. Diskobj:           dc.l   0
  244. CLIpoint:          dc.l   0
  245. Filename:          dc.l   0
  246. NewLock:           dc.l   0
  247. ParLock:           dc.l   0
  248. Inname:            dc.l   0
  249. Outname:           dc.l   0
  250. Pathstart:         dc.l   0
  251. Dosname:           dc.b   'dos.library',0
  252.                    align
  253. Iconname:          dc.b   'icon.library',0
  254.                    align
  255. TempNamn:          blk.b  32,0
  256.                    align
  257. Path:              blk.b  255,0
  258.                    align
  259. typeName1:         dc.b   "FILENAME",0,0
  260.                    align
  261. typeName2:         dc.b   "WINDOW",0,0
  262.                    align
  263. Textfld:           dc.b   27,"[33mNewEx Version 1.1 by Kjell Cederfeldt",13,10,10
  264.                    dc.b   "No file name or file not found!",27,"[31m",13,10,10
  265.                    align
  266. toolTypeArray:     dc.l   0
  267. IconText:          dc.l   0
  268. FileInfoblock:     blk.b  260,0
  269.                    align
  270.  
  271. ;                                 ReturnCode 47 = icon.library not open
  272. ;                                 ReturnCode 46 = dos.library  not open
  273. ;                                 ReturnCode 45 = currentdir not lock
  274. ;                                 ReturnCode 44 = diskobjekt not found
  275. ;                                 ReturnCode 43 = outfile (device) not found
  276. ;                                 ReturnCode 42 = infile (device) not found
  277.  
  278. ;********************   Subrutiner   ***************************************
  279.  
  280. PointTOCLI:
  281.  
  282. ; Output functionen point to cli-window already open if start from CLI
  283.  
  284.                    move.l Dosbase,a6                  ;pointer doslibrary
  285.                    jsr    OutPut(a6)                  ;get output pointer to Dos!
  286.                    move.l d1,CLIpoint                 ;Save pointer
  287.                    rts
  288.  
  289. ;***************************************************************************
  290.  
  291. GetPath:
  292.                    move.l #Path,d2                    ;peek on address to Path
  293.                    add.l  #253,d2                     ;peek on end -2
  294.                    move.l d2,PathStart                ;Get start of pathstring
  295.  
  296.                    move.l Dosbase,a6                  ;Load dosbase
  297.                    move.l #Filename,d1                ;Load pointer to filename
  298.                    move.l Access_read,d2              ;read-mode only
  299.                    jsr    Lock(a6)                    ;lock
  300.                    tst.l  d0
  301.                    beq    EndLoop                     ;No File found
  302.                    move.l d0,NewLock                  ;save lock
  303.  
  304. MainLoop:          move.l NewLock,d1                  ;Get lock
  305.                    move.l #Fileinfoblock,d2           ;Get address to block
  306.                    jsr    Examine(a6)                 ;Get fileinfo
  307.                    tst.l  d0
  308.                    beq    EndLoop
  309.  
  310.                    move.l #Fileinfoblock,d2
  311.                    add.l  #8,d2                       ;Add offset to address
  312.  
  313.                    clr.l  d0                          ;Clear counter
  314.                    move.l d2,a0                       ;move filepointer to A0
  315.                    move.l #Tempnamn,a1                ;move pathpointer to A1
  316. Loop:              move.b (a0)+,(a1)+                 ;move value A0 => A1
  317.                    add.l  #1,d0                       ;decriment counter
  318.  
  319.                    tst.b  (a0)                        ;Name end? (0 terminering)
  320.                    bne.s  Loop                        ;No branch to loop
  321.  
  322.                    move.b #47,(a1)+                   ;add '/'
  323.                    add.l  #1,d0                       ;decriment counter
  324.  
  325.                    move.l Pathstart,d2                ;get Path start
  326.                    move.l d2,a0
  327.  
  328. Loop2:             move.b -(a1),-(a0)                 ;save path-stukturen to Path
  329.                    sub.l  #1,d0                       ;increment counter
  330.                    bne.s  Loop2
  331.  
  332.                    move.l a0,Pathstart                ;save pathstart
  333.  
  334.                    move.l NewLock,d1                  ;get lock
  335.                    jsr    ParentDir(a6)               ;go to parent dir
  336.                    move.l d0,ParLock                  ;save lock
  337.                    move.l NewLock,d1                  ;get lock
  338.                    jsr    UnLock(a6)                  ;relese lock
  339.                    move.l ParLock,d0                  ;get lock
  340.                    move.l d0,NewLock                  ;move lock
  341.                    tst.l  d0                          ;are we in root ?
  342.                    bne    MainLoop                    ;No branch
  343.  
  344.                    move.l PathStart,a1                ;get pathstart
  345. Kolon:             cmp.b  #47,(a1)+                   ;found first '/'
  346.                    bne.s  kolon
  347.                    move.b #58,-(a1)                   ;Change this to ':'
  348.  
  349.                    move.l PathStart,a1                ;get pathstart
  350.                    move.b #34,-(a1)                   ;add '"'
  351.                    move.b #32,-(a1)                   ;add ' '
  352.                    move.b #68,-(a1)                   ;add 'D'
  353.                    move.b #67,-(a1)                   ;add 'C'
  354.                    move.l a1,PathStart                ;save the new start                   move.l #Path,a1
  355.                    add.l  #253,a1
  356.                    move.b #34,(a1)
  357.  
  358. Endloop:           rts
  359.  
  360. ;***************************************************************************
  361.                    end
  362.